package org.example.com.kotlinlab.delegate.class_delegate.demo02

interface Base {
    fun printMessage()
    fun printMessageLine()
}

class BaseImpl(val x: Int) : Base {
    override fun printMessage() {
        print(x)
    }

    override fun printMessageLine() {
        println(x)
    }
}

/**
 * 代理类可以重写被代理类方法
 */
class Derived(b: Base) : Base by b {
    override fun printMessage() {
        print("abc")
    }
}

fun main() {
    val b = BaseImpl(10)
    val derived = Derived(b)
    derived.printMessage()
    derived.printMessageLine()
}